

package com.yz.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yz.common.entity.*;
import com.yz.dao.DrawingDao;
import com.yz.dao.VedioDao;
import com.yz.service.CheckService;
import com.yz.service.DrawingService;
import com.yz.service.ProjectService;
import com.yz.service.VedioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.util.List;

@Service("vedioService")
public class VedioServiceImpl extends ServiceImpl<VedioDao,VedioEntity> implements VedioService {
    @Autowired
    CheckService checkService;
    @Autowired
    ProjectService projectService;

    @Override
    public long selectId() {
        return this.baseMapper.selectId();
    }
    @Override
    @Transactional(rollbackFor=Exception.class)
    public void postMe(VedioEntity t) {
        CheckEntity check = new CheckEntity();
        check.setCreateAt(t.getUpdateAt());
        check.setCreateUser(t.getCreateUser());
        check.setName(projectService.selectById(t.getProjectId()).getName());
        if(t.getTypeWhere()==1){
            check.setNameForm(contant.type_name[6]);
        }else {
            check.setNameForm(contant.type_name[7]);
        }
        check.setProjectId(t.getProjectId());
        check.setStatus(1);
        check.setType(4);
        check.setTypeForm(t.getTypeWhere());
        if(t.getId()==0){
            this.baseMapper.insert(t);
            long id = this.baseMapper.selectId();
            check.setDataId(id);
            check.setNumber(contant.type_all_form[3]+contant.type_detail_form[12]+id);
            checkService.insert(check);
        }else{
            long id = t.getId();
            check.setDataId(id);
            check.setNumber(contant.type_all_form[3]+contant.type_detail_form[12]+id);
            checkService.update(check,new EntityWrapper<CheckEntity>().eq("number",contant.type_all_form[3]+contant.type_detail_form[12]+id));
            this.baseMapper.update(t,new EntityWrapper<VedioEntity>().eq("id",id));
        }
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public void deleteMe(long id) {
        this.baseMapper.deleteById(id);
            checkService.deleteMe(4,id);
    }

//    public static String processImg(String veido_path,String ffmpeg_path) {
//        File file = new File(veido_path);
//        if (!file.exists()) {
//            System.err.println("路径[" + veido_path + "]对应的视频文件不存在!");
//            return null;
//        }
//        List<String> commands = new java.util.ArrayList<String>();
//        commands.add(ffmpeg_path);
//        commands.add("-i");
//        commands.add(veido_path);
//        commands.add("-y");
//        commands.add("-f");
//        commands.add("image2");
//        commands.add("-ss");
//        commands.add("1");//这个参数是设置截取视频多少秒时的画面
//        commands.add("-t");
//        commands.add("0.001");
//        commands.add("-s");
//        commands.add("1920x1080");//宽X高
//        String imgUrl = veido_path.substring(0, veido_path.lastIndexOf(".")).replaceFirst("vedio", "file") + ".jpg";
//        commands.add(imgUrl);
//        try {
//            ProcessBuilder builder = new ProcessBuilder();
//            builder.command(commands);
//            builder.start();
//            System.out.println("截取成功");
//            return imgUrl;
//        } catch (Exception e) {
//            e.printStackTrace();
//            return null;
//        }
//    }
}
